!execute 'dl.bat'
;!delfile "$%TEMP%\simplyplay_upx.tmp"
!define UPXParams '"upx.exe --best --crp-ms=999999 --nrv2d -o $%TEMP%\simplyplay_upx.tmp ..\Project1.exe"'
!system ${UPXParams}

!include "MUI2.nsh"

SetCompressor lzma

!define PRODUCT_NAME "SimplyPlay"

Name "${PRODUCT_NAME}"
OutFile "..\Install_${PRODUCT_NAME}.exe"

InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"

;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\${PRODUCT_NAME}" ""

;Request application privileges for Windows Vista
RequestExecutionLevel admin

;Interface Settings
!define MUI_ABORTWARNING

;Pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
  
;Languages
!insertmacro MUI_LANGUAGE "English"

;Installer Sections
Section "${PRODUCT_NAME}" Sec1
  SectionIn RO
  SetOutPath "$INSTDIR"
  
  File /oname=simplyplay.exe "$%TEMP%\simplyplay_upx.tmp"
  File "..\bass.dll"
  File "..\bass_aac.dll"
  File "..\bass_alac.dll"
  File "..\bass_flac.dll"
  File "..\bass_mpc.dll"
  File "..\bass_wma.dll"
  File "..\common.dll"
  File "..\ID3v2DLL.dll"
  File "..\sqlite3.dll"
  File "..\DejaVuSans.ttf"
  File "..\DejaVuSansCondensed.ttf"
  File "..\GPL.txt"
  CreateDirectory "$INSTDIR\SavedLists"

  ;Store installation folder
  WriteRegStr HKCU "Software\${PRODUCT_NAME}" "" $INSTDIR
  
  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayName" "${PRODUCT_NAME}"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "NoRepair" 1
  
  ;Create uninstaller
  WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd

Section "Start Menu Shortcuts" Sec2
  CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
  CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\simplyplay.exe" "" "$INSTDIR\simplyplay.exe" 0
SectionEnd

Section "Desktop Shortcut" Sec3
  CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\simplyplay.exe" "" "$INSTDIR\simplyplay.exe" 0
SectionEnd

Section "Quick Launch Shortcut" Sec4
  CreateShortCut "$QUICKLAUNCH\${PRODUCT_NAME}.lnk" "$INSTDIR\simplyplay.exe" "" "$INSTDIR\simplyplay.exe" 0
SectionEnd

;Descriptions
LangString DESC_Sec1 ${LANG_ENGLISH} "Program files. They are required."
LangString DESC_Sec2 ${LANG_ENGLISH} "Creates shortcuts in Start menu."
LangString DESC_Sec3 ${LANG_ENGLISH} "Creates shortcut on Desktop."
LangString DESC_Sec4 ${LANG_ENGLISH} "Creates quick launch shortcut."

;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${Sec1} $(DESC_Sec1)
  !insertmacro MUI_DESCRIPTION_TEXT ${Sec2} $(DESC_Sec2)
  !insertmacro MUI_DESCRIPTION_TEXT ${Sec3} $(DESC_Sec3)
  !insertmacro MUI_DESCRIPTION_TEXT ${Sec4} $(DESC_Sec4)
!insertmacro MUI_FUNCTION_DESCRIPTION_END

;Uninstaller Section
Section "Uninstall"

  RMDir /r "$INSTDIR"

  Delete "$SMPROGRAMS\${PRODUCT_NAME}\*.*"
  RMDir "$SMPROGRAMS\${PRODUCT_NAME}"

  Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
  Delete "$QUICKLAUNCH\${PRODUCT_NAME}.lnk"

  DeleteRegKey /ifempty HKCU "Software\${PRODUCT_NAME}"
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"

SectionEnd
